package org.activequant.util.ib;

import java.util.ArrayList;
import java.util.List;

public enum IBIndustry {


	
	FINANCIAL("Financial"),
	FUNDS("Funds"),
	
	CONSUMER_CYCLICAL("Consumer, Cyclical"),
	
	INDUSTRIAL("Industrial"),
	
	DIVERSIFIED("Diversified"),

	INDICES("Indices"),
	BASIC_MATERIALS("Basic Materials"),
	
	UTILITIES("Utilities"),
	
	GOVERNMENT("Government"),
	
	
	COMMUNICATIONS("Communications"),
	ENERGY("Energy"),
	
	CONSUMER_NON_CYCLICAL("Consumer, Non-cyclical"),
	
	TECHNOLOGY("Technology");
	/**
	 * private String value;
	 */
	private String value;
	/**
	 * List&lt;IBCategory&gt; categories=null;
	 */
	List<IBCategory> categories=null;
	/**
	 * find and returns categories(List&lt;IBCategory&gt;) categories belonging to this industry
	 * @return
	 */
	public List<IBCategory> getCategories(){
		if(categories==null){
			categories=new ArrayList<IBCategory>();
			for(IBCategory category:IBCategory.values()){
				if(category.getIndustry()==this){
					categories.add(category);
				}
			}
		}
		return categories;
	}
	/**
	 * constructs an IBIndustry enum with the given value
	 * @param value
	 */
	IBIndustry(String value) {
		this.value = value;
	}
	
	public String toString() {
		return value;
	}
	/**
	 * Returns the IBIndustry enum whose desc(String) matches the given value(String).
	 * Throws an IllegalArgumentException if it can't find such enum
	 * @param value
	 * @return
	 */
	public static IBIndustry toClass(String value) {
		for(IBIndustry symbol: values()) {
			if(symbol.toString().equals(value)) {
				return symbol;
			}
		}
		throw new IllegalArgumentException("Value '"+value+"' not defined as constant.");
	}

	public String getValue() {
		return value;
	}

}
